package com.hw.common.framework.exception;

import java.io.PrintWriter;
import java.io.StringWriter;

/*****
 * <pre>
 * 类名称：BaseException
 * 类描述：基础异常类
 * 创建人：JokenWang
 * 创建时间：2015年9月6日 下午4:16:10
 * </pre>
 * 
 * @version 1.0.0
 */
public class BaseException extends RuntimeException
{
    private static final long serialVersionUID = 3570550101569053089L;
    
    private String code;
    
    private String msg;
    
    public String getMsg()
    {
        return msg;
    }

    public void setMsg(String msg)
    {
        this.msg = msg;
    }

    public String getCode()
    {
        return code;
    }

    public void setCode(String code)
    {
        this.code = code;
    }

    public static String stackTraceToString(Exception e)
    {
        try
        {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            return sw.toString();
        }
        catch (Exception e2)
        {
            return "bad stack2string";
        }
    }
    
    public BaseException()
    {
    
    }
    
    public BaseException(String errorCode, String errorMsg, Throwable cause)
    {
        super("errorCode:" + errorCode + ",errorMsg:" + errorMsg, cause);
        setCode(errorCode);
        setMsg(errorMsg);
    }
    
    public BaseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)
    {
        super(message, cause, enableSuppression, writableStackTrace);
    }
    
    public BaseException(String message, Throwable cause)
    {
        super(message, cause);
    }
    
    public BaseException(String message)
    {
        super(message);
    }
    
    public BaseException(Throwable cause)
    {
        super(cause);
    }
}
